package com.luoran.bartalks.service.impl;

import java.util.List;

import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.luoran.bartalks.dao.IBtMaterielDao;
import com.luoran.bartalks.entity.BaseInfo;
import com.luoran.bartalks.entity.biz.BtMateriel;
import com.luoran.bartalks.service.IBtMaterielService;

@Service
public class BtMaterielService implements IBtMaterielService {

	@Autowired
	private IBtMaterielDao dao;

	@Override
	public PageQuery<? extends BaseInfo> getQueryList(PageQuery<? extends BaseInfo> pageQuery) {
		dao.queryPage(pageQuery);
		return pageQuery;
	}

	// 新增
	@Override
	public String addBtMateriel(BtMateriel btMateriel) {
		dao.insertTemplate(btMateriel);
		return btMateriel.getId();
	}

	// 根据编码查询物料.检测编码是否被占用
	@Override
	public BtMateriel getMaterielByMaterielCode(String materielCode, String companyId) {
		return dao.getMaterielByMaterielCode(materielCode, companyId);
	}

	// 分类是否被引用
	@Override
	public List<BtMateriel> getMaterielByTypeId(String companyId, String typeId) {
		return dao.getMaterielByTypeId(companyId, typeId);
	}

	// 根据主键查询
	@Override
	public BtMateriel getBtMateriel(String id) {
		return dao.single(id);
	}

	// 根据主键更新
	@Override
	public int updateMaterielById(BtMateriel btMateriel) {
		return dao.updateTemplateById(btMateriel);
	}

	// 扫描货物时需要根据货物id和公司id校验货物
	@Override
	public BtMateriel getBtMaterielByIdAndCompanyId(String materielId, String companyId) {

		return dao.getBtMaterielByIdAndCompanyId(materielId, companyId);
	}

}